package org.jet.emall.prod.transfer;

import org.jet.emall.prod.custom.po.AttrPO;
import org.jet.emall.prod.custom.po.SpecPO;
import org.jet.emall.prod.dto.*;
import org.jet.emall.prod.po.ProdSku;
import org.jet.emall.prod.po.ProdSkuImage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author xiaozai
 * @version 1.0
 * @date 2020-04-15 12:02
 */
@Mapper
public interface SkuDtoTransfer {

    SkuDtoTransfer INSTANCE = Mappers.getMapper(SkuDtoTransfer.class);


    /**
     *  将SKU 的PO对象 转DTO对象
     * @param sku
     * @return
     */
    @Mappings({
            @Mapping(target = "attrs",ignore = true),
            @Mapping(target = "specs",ignore = true),
            @Mapping(target = "images",ignore = true)
    })
    SkuDetailsDTO toDetailsDto(ProdSku sku);

    /**
     *  将属性PO列表转为DTO列表
     * @param attrPOList
     * @return
     */
    List<AttrDTO> toAttrDtoList(List<AttrPO> attrPOList);

    /**
     *  将规格PO列表转为DTO列表
     * @param specPOList
     * @return
     */
    List<SpecDTO> toSpecDtoList(List<SpecPO> specPOList);

    /**
     *  将SKU图片PO列表转DTO列表
     * @param list
     * @return
     */
    List<SkuImageDTO> toImageDtoList(List<ProdSkuImage> list);

    /**
     *  将SKU DTO转PO
     * @param dto
     * @return
     */
    @Mappings({
            @Mapping(target = "deleted", ignore = true),
            @Mapping(target = "modifiedTime",ignore = true)
    })
    ProdSku toPo(SkuDetailsDTO dto);

    /**
     *  将新建的SKU的DTO转PO
     * @param dto
     * @return
     */
    ProdSku toPo(NewSkuDTO dto);

    /**
     *  将SKU图片DTO列表转PO列表
     * @param images
     * @return
     */

    List<ProdSkuImage> toImagePoList(List<SkuImageDTO> images);

    /**
     *  将SKU的PO列表转DTO列表
     * @param list
     * @return
     */
    List<SkuDTO> toDtoList(List<ProdSku> list);

    /**
     *  将SKU图片DTO转PO
     * @param dto
     * @return
     */
    @Mapping(target = "deleted",ignore = true)
    ProdSkuImage toImagePo(SkuImageDTO dto);
}
